package by.jtraining.london.service.impl;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.inject.persist.Transactional;

import by.jtraining.london.repo.GenericRepository;
import by.jtraining.london.service.GenericService;


public abstract class GenericServiceImpl <E, ID extends Serializable, R extends GenericRepository<E, ID>>
implements GenericService <E, ID>{
	 private static final Logger LOG = LoggerFactory
			.getLogger(GenericServiceImpl.class);
	 
	 protected final R repo;
	 public GenericServiceImpl(R repo) {
		    this.repo = Preconditions.checkNotNull(repo);
		  }
	 @Transactional
	  @Override
	  public List<E> findAll() {
		LOG.debug("Find all persisted objects:");
	    return repo.findAll();
	  }

	  @Transactional
	  @Override
	  public E getById(ID id) {
	 LOG.debug("Get object:");
	    return repo.getById(id);
	  }

	  @Transactional
	  @Override
	  public void save(E entity) {
		  LOG.debug("Update object:");	  
	    repo.save(entity);
	  }

}
